package com.gba.mark.exam.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gba.mark.exam.entity.ExamAnswer;
import com.gba.mark.exam.entity.ExamQuestions;
import com.gba.mark.exam.entity.ExamResult;
import com.gba.mark.exam.service.ExamAnswerService;
import com.gba.mark.exam.service.ExamResultService;
import com.gba.mark.group.entity.Group;
import com.gba.mark.group.service.IGroupService;
import com.gba.mark.user.auth.utils.AuthUtils;
import com.gba.mark.user.entity.user.User;
import com.gba.mark.user.service.user.IUserService;
import com.gba.mark.util.ResponseUtil;
//import com.qigetech.utils.resultbundle.ResultBundleBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
    @RequestMapping("/exam/result")
    public class ExamResultController {

        @Autowired
        private ExamResultService examResultService;

        @Autowired
        private ExamAnswerService examAnswerService;


        @Autowired
        private IUserService userServiceImpl;

        @Autowired
        private IGroupService groupService;
//        @Autowired
//        private ResultBundleBuilder resultBundleBuilder;
    /**
     * 新建并保存一份考试结果
     */
//    @PostMapping("/saveResult")
//    public ResponseUtil<Integer> saveResult(//Authentication authentication,
//                                        @RequestBody String answer,
//                                        @RequestBody List<ExamAnswer> userAnswer){

    //String username = AuthUtils.getUsername(authentication);

    //User user = userServiceImpl.getOne(new QueryWrapper<User>().eq("username", username));
    //int admin_id = user.getId();
    //Group group = groupService.getOne(new QueryWrapper<Group>().eq("admin_id",admin_id));
    //String group_name = group.getName();

   // ExamAnswer examAnswer = examAnswerService.getOne(new QueryWrapper<ExamAnswer>().eq("user_answer", userAnswer));
//        int user_id = examAnswer.getUserId();
//        GroupMember groupMember = groupMemberService.getOne(new QueryWrapper<GroupMember>().eq("user_id", user_id));
//        int group_id =groupMember.getGroup_id();
//
//        return new ResponseUtil<>(HttpStatus.OK,"",examResultService.saveResult(answer, userAnswer, user_id, group_id));
//
//    }
}
